import {defineStore} from "pinia";
import {ref} from "vue";

export const useOrderInfoStore = defineStore('orderInfoStore', () => {
    // 订单信息
    const orderInfo = ref({
        userId: 0,
        shopId: 0
    })
    // 地址信息
    const addrInfo = ref({
        // 用户收货地址id
        id: 0,
        // 收货人姓名
        name: '',
        // 地址
        address: '',
        // 电话
        phone: '',
        // 是否为默认地址
        status: 0
    })
    // 购买后的商品信息
    const goodsInfo = ref({
        // 购买人id
        id: 0,
        // 商品id
        goods_id: 0,
        // 图片
        img: '',
        // 商品标题
        title: '',
        // 商品价格
        totalPrice: '',
        // 商品外观
        look: '',
        // 商品版本
        version: '',
        // 商品数量
        count: 1
    })

    const setOrderImg = (img) => {
      goodsInfo.value.img = img
    }
    const setGoodsInfo = ({id, goods_id, title, totalPrice, look, version, count}) => {
        goodsInfo.value.id = id
        goodsInfo.value.goods_id = goods_id
        goodsInfo.value.title = title
        goodsInfo.value.totalPrice = totalPrice
        goodsInfo.value.look = look
        goodsInfo.value.version = version
        goodsInfo.value.count = count
    }
    const setUserId = (id) => {
        orderInfo.value.userId = id
    }

    const setAddrInfo = ({id, name, address, phone, status}) => {
        addrInfo.value.id = id
        addrInfo.value.name = name
        addrInfo.value.address = address
        addrInfo.value.phone = phone
        addrInfo.value.status = status
    }

    return {
        orderInfo,
        setUserId,
        setAddrInfo,
        addrInfo,
        goodsInfo,
        setGoodsInfo,
        setOrderImg
    }
}, {
    persist: true
})